#include "frm_beats.h"
#include "ui_frm_beats.h"
#include "frm_menu.h"
#include "frm_beats_aca.h"
#include <QTimer>
#include <cstdio>
#include <QString>
#include <QDesktopWidget>

frm_beats::frm_beats(QDialog *back, QDialog *parent) :
    QDialog(parent),
    ui(new Ui::frm_beats)
{
    ui->setupUi(this);
    back_=back;
    timer = new QTimer(this);
    setWindowFlags( Qt:: WindowTitleHint | Qt:: CustomizeWindowHint | Qt:: WindowMinimizeButtonHint | Qt:: WindowMaximizeButtonHint);
    this->move(QApplication::desktop()->screen()->rect().center() - this->rect().center());
}

frm_beats::~frm_beats()
{
    delete ui;
}

void frm_beats::on_b_start_clicked()
{
    connect(timer,SIGNAL(timeout()),this,SLOT(updateCuenta()));
    timer->start(1000);
    this->ui->b_start->setEnabled(false);
    this->ui->b_back->setEnabled(false);
}

void frm_beats::on_b_back_clicked()
{
    this->hide();
    back_->show();
}

void frm_beats::updateCuenta(){
    QString texto=ui->e_time->text();
    int segundos = texto.toInt();
    if(segundos > 0){
        --segundos;
        char cadena[2];
        sprintf(cadena,"%d",segundos);
        ui->e_time->setText(cadena);
    }
    else if(segundos > -2){
        this->hide();
        frm_beats_aca *aca = new frm_beats_aca(back_);
        aca->show();
        timer->stop();
    }
    return;
}
